package com.ruoyi.web.controller.match;

import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.squadweb.domain.SquadMatchTeamCompareInfo;
import com.ruoyi.squadweb.service.ISquadMatchTeamCompareInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 比赛场次信息Controller
 *
 * @author LJY
 * @date 2024-07-13
 */
@RestController
@RequestMapping("/web/info")
public class SquadMatchTeamCompareInfoController extends BaseController
{
    @Autowired
    private ISquadMatchTeamCompareInfoService squadMatchTeamCompareInfoService;

    /**
     * 查询比赛场次信息列表
     */
    @GetMapping("/getInfo")
    public TableDataInfo getInfo(String date) {
        if (StringUtils.isEmpty(date)) {
            throw new RuntimeException("日期不能为空");
        }
        SquadMatchTeamCompareInfo squadMatchTeamCompareInfo = new SquadMatchTeamCompareInfo();
        squadMatchTeamCompareInfo.setDate(DateUtils.dateTime("yyyy/MM/dd", date));
        List<SquadMatchTeamCompareInfo> list = squadMatchTeamCompareInfoService.selectSquadMatchTeamCompareInfoList(squadMatchTeamCompareInfo);
        return getDataTable(list);
    }

    /**
     * 获取前后七天的日期
     */

    @GetMapping("/week/list")
    public AjaxResult weekList() {
        List<Map<String, String>> weekList = new ArrayList<>();
        LocalDate today = LocalDate.now();

        for (int i = 1; i <= 14; i++) {
            Map<String, String> week = new HashMap<>();
            LocalDate localDate = today.minusDays(8 - i);
            week.put("title", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant())));
            week.put("name", i + "");
            week.put("content", i + "");
            weekList.add(week);

        }
        return AjaxResult.success(weekList);
    }

    /**
     * 查询比赛场次信息列表
     */
    @GetMapping("/match/list")
    public TableDataInfo listMatch(SquadMatchTeamCompareInfo squadMatchTeamCompareInfo) {

        startPage();
        List<SquadMatchTeamCompareInfo> list = squadMatchTeamCompareInfoService.listMatch(squadMatchTeamCompareInfo);
        return getDataTable(list);
    }

    /**
     * 查询比赛场次信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SquadMatchTeamCompareInfo squadMatchTeamCompareInfo) {

        startPage();
        List<SquadMatchTeamCompareInfo> list = squadMatchTeamCompareInfoService.selectSquadMatchTeamCompareInfoList(squadMatchTeamCompareInfo);
        return getDataTable(list);
    }

    /**
     * 导出比赛场次信息列表
     */
    @Log(title = "比赛场次信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SquadMatchTeamCompareInfo squadMatchTeamCompareInfo)
    {
        List<SquadMatchTeamCompareInfo> list = squadMatchTeamCompareInfoService.selectSquadMatchTeamCompareInfoList(squadMatchTeamCompareInfo);
        ExcelUtil<SquadMatchTeamCompareInfo> util = new ExcelUtil<SquadMatchTeamCompareInfo>(SquadMatchTeamCompareInfo.class);
        util.exportExcel(response, list, "比赛场次信息数据");
    }

    /**
     * 获取比赛场次信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(squadMatchTeamCompareInfoService.selectSquadMatchTeamCompareInfoById(id));
    }

    /**
     * 新增比赛场次信息
     */
    @Log(title = "比赛场次信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SquadMatchTeamCompareInfo squadMatchTeamCompareInfo)
    {
        return toAjax(squadMatchTeamCompareInfoService.insertSquadMatchTeamCompareInfo(squadMatchTeamCompareInfo));
    }

    /**
     * 修改比赛场次信息
     */
    @Log(title = "比赛场次信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SquadMatchTeamCompareInfo squadMatchTeamCompareInfo)
    {
        return toAjax(squadMatchTeamCompareInfoService.updateSquadMatchTeamCompareInfo(squadMatchTeamCompareInfo));
    }

    /**
     * 删除比赛场次信息
     */
    @Log(title = "比赛场次信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(squadMatchTeamCompareInfoService.deleteSquadMatchTeamCompareInfoByIds(ids));
    }
}
